package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.common.ConsoleConstant;
import com.fdb.efp.nls.service.dao.LmtTerminateAppDao;
import com.fdb.efp.nls.service.domain.LmtTerminateApp;
import com.fdb.efp.nls.service.facade.LmtTerminateAppService;
import com.fdb.efp.nls.service.vo.LmtTerminateAppVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 额度终止申请表				<p>
 * @author ligm
 * @date 2019-08-10
 */
@Service("lmtTerminateAppService")
public class LmtTerminateAppServiceImpl implements LmtTerminateAppService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(LmtTerminateAppServiceImpl.class);

	@Autowired
	private LmtTerminateAppDao lmtTerminateAppDao;
	
	/**
	 * 新增操作
	 */
	public int insertLmtTerminateApp(LmtTerminateAppVO inLmtTerminateAppVo) {
		logger.debug("当前新增数据为:"+ inLmtTerminateAppVo.toString());
		int num = 0;
		try {
			LmtTerminateApp lmtTerminateApp = new LmtTerminateApp();
			beanCopy(inLmtTerminateAppVo, lmtTerminateApp);
			num = lmtTerminateAppDao.insertLmtTerminateApp(lmtTerminateApp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(LmtTerminateAppVO inLmtTerminateAppVo) {
		logger.debug("当前删除数据条件为:"+ inLmtTerminateAppVo);
		int num = 0;
		try {
			LmtTerminateApp lmtTerminateApp = new LmtTerminateApp();
			beanCopy(inLmtTerminateAppVo, lmtTerminateApp);
			num = lmtTerminateAppDao.deleteByPk(lmtTerminateApp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inLmtTerminateAppVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(LmtTerminateAppVO inLmtTerminateAppVo) {
		logger.debug("当前修改数据为:"+ inLmtTerminateAppVo.toString());
		int num = 0;
		try {
			LmtTerminateApp lmtTerminateApp = new LmtTerminateApp();
			beanCopy(inLmtTerminateAppVo, lmtTerminateApp);
			num = lmtTerminateAppDao.updateByPk(lmtTerminateApp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inLmtTerminateAppVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public LmtTerminateAppVO queryByPk(LmtTerminateAppVO inLmtTerminateAppVo) {
		
		logger.debug("当前查询参数信息为:"+ inLmtTerminateAppVo);
		try {
			LmtTerminateApp queryLmtTerminateApp = new LmtTerminateApp();
			beanCopy(inLmtTerminateAppVo, queryLmtTerminateApp);
			LmtTerminateApp queryRslLmtTerminateApp = lmtTerminateAppDao.queryByPk(queryLmtTerminateApp);
			if (Objects.nonNull(queryRslLmtTerminateApp)) {
				LmtTerminateAppVO outLmtTerminateAppVo = beanCopy(queryRslLmtTerminateApp, new LmtTerminateAppVO());
				logger.debug("当前查询结果为:"+ outLmtTerminateAppVo.toString());
				return outLmtTerminateAppVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtTerminateAppVO> queryAllOwner(LmtTerminateAppVO lmtTerminateAppVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<LmtTerminateAppVO> list = null;
		try {
			List<LmtTerminateApp> lmtTerminateApps = lmtTerminateAppDao.queryAllOwnerByPage(lmtTerminateAppVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ lmtTerminateApps.size());
			pageSet(lmtTerminateApps, lmtTerminateAppVo);
			list = (List<LmtTerminateAppVO>) beansCopy(lmtTerminateApps, LmtTerminateAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtTerminateAppVO> queryAllCurrOrg(LmtTerminateAppVO lmtTerminateAppVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<LmtTerminateApp> lmtTerminateApps = lmtTerminateAppDao.queryAllCurrOrgByPage(lmtTerminateAppVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+lmtTerminateApps.size());
		List<LmtTerminateAppVO> list = null;
		try {
			pageSet(lmtTerminateApps, lmtTerminateAppVo);
			list = (List<LmtTerminateAppVO>) beansCopy(lmtTerminateApps, LmtTerminateAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtTerminateAppVO> queryAllCurrDownOrg(LmtTerminateAppVO lmtTerminateAppVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<LmtTerminateApp> lmtTerminateApps = lmtTerminateAppDao.queryAllCurrDownOrgByPage(lmtTerminateAppVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ lmtTerminateApps.size());
		List<LmtTerminateAppVO> list = null;
		try {
			pageSet(lmtTerminateApps, lmtTerminateAppVo);
			list = (List<LmtTerminateAppVO>) beansCopy(lmtTerminateApps, LmtTerminateAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	/**
	 * 查询当前授信协议的全部数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtTerminateAppVO> queryByLmtContNo(LmtTerminateAppVO inLmtTerminateAppVo) {
		logger.debug("当前查询参数信息为:"+ inLmtTerminateAppVo);
		List<LmtTerminateAppVO> list = null;
		try {
			LmtTerminateApp lmtTerminateApp = new LmtTerminateApp();
			beanCopy(inLmtTerminateAppVo, lmtTerminateApp);
			List<LmtTerminateApp> queryRs = lmtTerminateAppDao.queryAllByLmtContNo(lmtTerminateApp);
			logger.debug("当前查询授信协议审批中的结果集数量为:" + queryRs.size());
			pageSet(queryRs, inLmtTerminateAppVo);
			list = (List<LmtTerminateAppVO>) beansCopy(queryRs, LmtTerminateAppVO.class);
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return list;
	}

	/**
	 * 查询审批中的额度终止申请
	 * */
	@Override
	public List<LmtTerminateAppVO> querylmtTerminateByPk(LmtTerminateAppVO lmtFreezeAppVO) {
		logger.debug("当前查询授信协议审批中的参数信息为:" + lmtFreezeAppVO.getLmtContNo());
		List<LmtTerminateAppVO> list = null;
		LmtTerminateAppVO lmtTerminateAppVO = new LmtTerminateAppVO();
		lmtTerminateAppVO.setLmtContNo(lmtFreezeAppVO.getLmtContNo());
		lmtTerminateAppVO.setApproveStatus(ConsoleConstant.APRV_STATUS_02);
		try {
			List<LmtTerminateApp> lmtTerminateApps = lmtTerminateAppDao.querylmtTerminateByPk(lmtTerminateAppVO);
			logger.debug("当前查询授信协议审批中的结果集数量为:" + lmtTerminateApps.size());
			pageSet(lmtTerminateApps, lmtTerminateAppVO);
			list = (List<LmtTerminateAppVO>) beansCopy(lmtTerminateApps, LmtTerminateAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public List<LmtTerminateAppVO> queryAllByCoditions(LmtTerminateAppVO lmtTerminateAppVO) {
		logger.debug("当前查询的参数信息为:" + lmtTerminateAppVO);
		List<LmtTerminateAppVO> list = null;
		try {
			List<LmtTerminateApp> lmtTerminateApps = lmtTerminateAppDao.queryAllByCoditionsByPage(lmtTerminateAppVO);
			logger.debug("当前查询的结果集数量为:" + lmtTerminateApps.size());
			pageSet(lmtTerminateApps, lmtTerminateAppVO);
			list = (List<LmtTerminateAppVO>) beansCopy(lmtTerminateApps, LmtTerminateAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public List<LmtTerminateAppVO> queryAllCurrOwnerPrd(LmtTerminateAppVO lmtTerminateAppVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:"+lmtTerminateAppVo);
		List<LmtTerminateAppVO> list = null;
		try {
			LmtTerminateApp lmtTerminateApp = new LmtTerminateApp();
			beanCopy(lmtTerminateAppVo,lmtTerminateApp);
			List<LmtTerminateApp> lmtTerminateApps = lmtTerminateAppDao.queryAllCurrOwnerPrdByPage(lmtTerminateApp);
			logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ lmtTerminateApps.size());
			pageSet(lmtTerminateApps, lmtTerminateAppVo);
			list = (List<LmtTerminateAppVO>) beansCopy(lmtTerminateApps, LmtTerminateAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}
}
